using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class GMTabItem
{
    private Toggle toggle;
    private TMP_Text tmp_name;
    private Image img_bg;

    public GMTabItem(GameObject item, string group, Action<string> onSelect)
    {
        img_bg = item.transform.GetChild(0).GetComponent<Image>();
        tmp_name = item.transform.GetChild(1).GetComponent<TMP_Text>();
        tmp_name.text = group;
        toggle = item.GetComponent<Toggle>();
        toggle.onValueChanged.AddListener(b =>
        {
            if (b)
            {
                onSelect?.Invoke(group);
                img_bg.color = Color.gray;
            }
            else
            {
                img_bg.color = Color.white;
            }
        });
    }
}
